// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    var openid = ""

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        let that = this       
        if (res.code) {  
          if(wx.getStorageSync('openid') !=""&&wx.getStorageSync('openid') !=undefined)  {
            return
          }     
          wx.request({             
            method:"post",           
            // url:"http://121.37.180.71:8002/getWXInfo",
            url:'https://admin.yzqysoft.com:8002/getWXInfo',
            data: {
              appid:"wx2f6a5ce3765a80ae", //臻邦
              //appid:"wx34fa1743fa2c9078",
              code: res.code 
            },  
            header: {
              'content-type': 'application/json',
            },  
            success: res => {   
              //openid获取出错的情况
              if(res.data == "openid error"){
                wx.setStorageSync('openid', "")
                console.log("openid error")


                return
              }
              let openid = res.data
              wx.setStorageSync('openid', openid)
              
              if(openid!=undefined && openid != ""){
                //发送请求查看有没有 该用户对应的文件夹
                wx.request({
                  method:"POST",
                  //url: 'http://121.37.180.71:8002/makeWXDir',
                  url:'https://admin.yzqysoft.com:8002/makeWXDir',
                  data: {
                    dirname:openid.toString(),
                  },  
                  header: {
                    'content-type': 'application/json',
                  },  
                  success:function(res){
                    console.log(res)

                  },
                  fail:function(err){
                    console.log(err)
                  }
                })
              }else{
                console.log("openid==undefined || openid == \"\"")
              }              
            }
          })       
        }
      }
    })
  },
  globalData: {
    userInfo: null
  },

})
